package com.kafka.kafka.study;

import com.kafka.kafka.utils.PropertiesUtils;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;

import java.util.Properties;
import java.util.concurrent.ExecutionException;

/**
 * Project: tobe-better-coder
 * Package: com.kafka.kafka.study
 *
 * @author : Mr.xu
 * @date : 2023/9/10 15:34
 */
public class CustomProducerSync {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //1.创建配置
        Properties properties = PropertiesUtils.getKafkaProperties("node1:9092,node2:9092");

        //创建kafka生产者对象
        KafkaProducer<String,String> kafkaProducer = new KafkaProducer<>(properties);
        //发送消息 send方法本身是异步的，加上get后改为同步
        RecordMetadata metadata = kafkaProducer.send(new ProducerRecord<>("xuxin","hello kafka sync")).get();

        kafkaProducer.close();

    }
}